<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>使用xmake优雅地描述工程</title>
    <meta name="description" content="描述语法xmake的描述语法基于lua实现，因此描述语法继承了lua的灵活性和简洁性，并且通过28原则，将描述作用域（简单描述）、脚本作用域（复杂描述）进行分离，使得工程更加的简洁直观，可读性非常好。因为80%的工程，并不需要很复杂的脚本控制逻辑，只需要简单的几行配置描述，就可满足构建需求，基于这个假设，xmak...">

    
    <meta name="keywords" content="xmake,lua,工程描述,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/cn/2017/04/05/project-desciption-examples/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />

    <!-- css -->
    <link href="/css/reward.css" rel="stylesheet" type="text/css"> 




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/cn" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/?lang=0">
                    
                        <i class="fa fa-home"></i>English
                    </a>
                </li>

                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>项目
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/archive/">
                            
                        
                            <i class="fa fa-archive"></i>归档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/category/">
                            
                        
                            <i class="fa fa-th-list"></i>分类
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/tag/">
                            
                        
                            <i class="fa fa-tags"></i>标记
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/docs/">
                            
                        
                            <i class="fa fa-book"></i>文档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="https://xmake.io/#/zh-cn/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>社区
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/donation/">
                            
                        
                            <i class="fa fa-heart"></i>捐助
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/about/">
                            
                        
                            <i class="fa fa-user"></i>关于
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>使用xmake优雅地描述工程</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2017-04-05
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#xmake" title="Category: xmake" rel="category">xmake</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a-->
        <a href="/cn/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a>&nbsp;
    
        <!--a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a-->
        <a href="/cn/tag/#lua" title="Tag: lua" rel="tag">lua</a>&nbsp;
    
        <!--a href="/tag/#%E5%B7%A5%E7%A8%8B%E6%8F%8F%E8%BF%B0" title="Tag: 工程描述" rel="tag">工程描述</a-->
        <a href="/cn/tag/#工程描述" title="Tag: 工程描述" rel="tag">工程描述</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <h3 id="描述语法">描述语法</h3>

<p>xmake的描述语法基于lua实现，因此描述语法继承了lua的灵活性和简洁性，并且通过28原则，将描述作用域（简单描述）、脚本作用域（复杂描述）进行分离，使得工程更加的简洁直观，可读性非常好。</p>

<p>因为80%的工程，并不需要很复杂的脚本控制逻辑，只需要简单的几行配置描述，就可满足构建需求，基于这个假设，xmake分离作用域，使得80%的<code class="highlighter-rouge">xmake.lua</code>文件，只需要这样描述：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>而仅有的20%的工程，才需要这样描述：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">set_objectdir</span><span class="p">(</span><span class="s2">"$(buildir)/.objs"</span><span class="p">)</span>
    <span class="n">set_targetdir</span><span class="p">(</span><span class="s2">"libs/armeabi"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"jni/*.c"</span><span class="p">)</span>

    <span class="n">on_package</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span> 
        <span class="n">os</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"ant debug"</span><span class="p">)</span> 
    <span class="k">end</span><span class="p">)</span>

    <span class="n">on_install</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span> 
        <span class="n">os</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"adb install -r ./bin/Demo-debug.apk"</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>

    <span class="n">on_run</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span> 
        <span class="n">os</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"adb shell am start -n com.demo/com.demo.DemoTest"</span><span class="p">)</span>
        <span class="n">os</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"adb logcat"</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>上面的<code class="highlighter-rouge">function () end</code>部分属于自定义脚本域，一般情况下是不需要设置的，只有在需要复杂的工程描述、高度定制化需求的情况下，才需要自定义他们，在这个作用域可以使用各种xmake提供的扩展模块，关于这个的更多介绍，见：<a href="/cn/2016/10/26/api-scope/">xmake 描述语法和作用域详解</a>。</p>

<p>而上面的代码，也是一个自定义混合构建jni和java代码的android工程，可以直接通过<code class="highlighter-rouge">xmake run</code>命令，实现一键自动构建、安装、运行apk程序。</p>

<p>下面介绍一些比较常用的xmake描述实例：</p>

<h3 id="构建一个可执行程序">构建一个可执行程序</h3>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>这是一个最简单经典的实例，一般情况下，这种情况，你不需要自己写任何<code class="highlighter-rouge">xmake.lua</code>文件，在当前代码目录下，直接执行<code class="highlighter-rouge">xmake</code>命令，就可以完成构建，并且会自动帮你生成一个<code class="highlighter-rouge">xmake.lua</code>。</p>

<p>关于自动生成的详细信息，见：<a href="/cn/2017/01/07/build-without-makefile/">xmake智能代码扫描编译模式，无需手写任何make文件</a>。</p>

<h3 id="构建一个可配置切换的库程序">构建一个可配置切换的库程序</h3>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"$(kind)"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>可通过配置，切换是否编译动态库还是静态库：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake f --kind<span class="o">=</span>static; xmake
<span class="gp">$ </span>xmake f --kind<span class="o">=</span>shared; xmake
</code></pre>
</div>

<h3 id="增加debug和release编译模式支持">增加debug和release编译模式支持</h3>

<p>也许默认的几行描述配置，已经不能满足你的需求，你需要可以通过切换编译模式，构建debug和release版本的程序，那么只需要：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">set_symbols</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">)</span>
    <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"none"</span><span class="p">)</span>
<span class="k">end</span>

<span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"release"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">set_symbols</span><span class="p">(</span><span class="s2">"hidden"</span><span class="p">)</span>
    <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"fastest"</span><span class="p">)</span>
    <span class="n">set_strip</span><span class="p">(</span><span class="s2">"all"</span><span class="p">)</span>
<span class="k">end</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span> 
</code></pre>
</div>

<p>你只需要通过配置来切换构建模式：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake f -m debug; xmake
<span class="gp">$ </span>xmake f -m release; xmake
</code></pre>
</div>

<p><code class="highlighter-rouge">[-m|--mode]</code>属于内置选项，不需要自己定义<code class="highlighter-rouge">option</code>，就可使用，并且模式的值是用户自己定义和维护的，你可以在<code class="highlighter-rouge">is_mode("xxx")</code>判断各种模式状态。</p>

<h3 id="通过自定义脚本签名ios程序">通过自定义脚本签名ios程序</h3>

<p>ios的可执行程序，在设备上运行，需要在构建完成后进行签名，这个时候就可以使用自定义脚本来实现：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.m"</span><span class="p">)</span> 
    <span class="n">after_build</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">))</span>
        <span class="n">os</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"ldid -S %s"</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span><span class="n">targetfile</span><span class="p">())</span>
    <span class="k">end</span>
</code></pre>
</div>

<p>这里只是用ldid程序做了个假签名，只能在越狱设备上用哦，仅仅作为例子参考哈。</p>

<h3 id="内置变量和外置变量">内置变量和外置变量</h3>

<p>xmake提供了<code class="highlighter-rouge">$(varname)</code>的语法，来支持内置变量的获取，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cxflags</span><span class="p">(</span><span class="s2">"-I$(buildir)"</span><span class="p">)</span>
</code></pre>
</div>

<p>它将会在在实际编译的时候，将内置的<code class="highlighter-rouge">buildir</code>变量转换为实际的构建输出目录：<code class="highlighter-rouge">-I./build</code></p>

<p>一般内置变量可用于在传参时快速获取和拼接变量字符串，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"$(projectdir)/src/*.c"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"$(buildir)/inc"</span><span class="p">)</span>
</code></pre>
</div>

<p>也可以在自定义脚本的模块接口中使用，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">on_run</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span>
        <span class="n">os</span><span class="p">.</span><span class="n">cp</span><span class="p">(</span><span class="s2">"$(scriptdir)/xxx.h"</span><span class="p">,</span> <span class="s2">"$(buildir)/inc"</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>当然这种变量模式，也是可以扩展的，默认通过<code class="highlighter-rouge">xmake f --var=val</code>命令，配置的参数都是可以直接获取，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"-DTEST=$(var)"</span><span class="p">)</span>
</code></pre>
</div>

<p>既然支持直接从配置选项中获取，那么当然也就能很方便的扩展自定义的选项，来获取自定义的变量了，具体如何自定义选项见：<a href="http://xmake.io/#/zh/manual?id=option">option</a></p>

<h3 id="修改目标文件名">修改目标文件名</h3>

<p>我们可以通过内建变量，将生成的目标文件按不同架构和平台进行分离，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">set_basename</span><span class="p">(</span><span class="s2">"demo_$(arch)"</span><span class="p">)</span>
    <span class="n">set_targetdir</span><span class="p">(</span><span class="s2">"$(buildir)/$(plat)"</span><span class="p">)</span>
</code></pre>
</div>

<p>之前的默认设置，目标文件会生成为<code class="highlighter-rouge">build\demo</code>，而通过上述代码的设置，目标文件在不同配置构建下，路径和文件名也不尽相同，执行：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake f -p iphoneos -a arm64; xmake
</code></pre>
</div>

<p>则目标文件为：<code class="highlighter-rouge">build/iphoneos/demo_arm64</code>。</p>

<h3 id="添加子目录工程模块">添加子目录工程模块</h3>

<p>如果你有多个target子模块，那么可以在一个<code class="highlighter-rouge">xmake.lua</code>中进行定义，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/demo.c"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/test.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>但是，如果子模块非常多，那么放置在一个xmake文件，就显得有些臃肿了，可以放置到独立模块的子目录去：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/demo.c"</span><span class="p">)</span>

<span class="n">add_subdirs</span><span class="p">(</span><span class="s2">"src/test"</span><span class="p">)</span>
</code></pre>
</div>

<p>通过上述代码，关联一个子工程目录，在里面加上<code class="highlighter-rouge">test</code>的工程目标就行了。</p>

<h3 id="安装头文件">安装头文件</h3>

<div class="highlighter-rouge"><pre class="highlight"><code>target("tbox")
    set_kind("static")
    add_files("src/*.c")

    add_headers("../(tbox/**.h)|**/impl/**.h")
    set_headerdir("$(buildir)/inc")
</code></pre>
</div>

<p>安装好的头文件位置和目录结构为：<code class="highlighter-rouge">build/inc/tbox/*.h</code>。</p>

<p>其中<code class="highlighter-rouge">../(tbox/**.h)</code>带括号的部分，为实际要安装的根路径，<code class="highlighter-rouge">|**/impl/**.h</code>部分用于排除不需要安装的文件。</p>

<p>其通配符匹配规则、排除规则可参考<a href="http://xmake.io/#/zh/manual?id=targetadd_files">add_files</a>。</p>

<h3 id="多目标依赖构建">多目标依赖构建</h3>

<p>多个target工程目标，默认构建顺序是未定义的，一般按顺序的方式进行，如果你需要调整构建顺序，可以通过添加依赖顺序来实现：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test1"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"static"</span><span class="p">)</span>
    <span class="n">set_files</span><span class="p">(</span><span class="s2">"*.c"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test2"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"static"</span><span class="p">)</span>
    <span class="n">set_files</span><span class="p">(</span><span class="s2">"*.c"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">add_deps</span><span class="p">(</span><span class="s2">"test1"</span><span class="p">,</span> <span class="s2">"test2"</span><span class="p">)</span>
    <span class="n">add_links</span><span class="p">(</span><span class="s2">"test1"</span><span class="p">,</span> <span class="s2">"test2"</span><span class="p">)</span>
</code></pre>
</div>

<p>上面的例子，在编译目标demo的时候，需要先编译test1, test2目标，因为demo会去用到它们。</p>

<h3 id="合并静态库">合并静态库</h3>

<p>xmake的<a href="http://xmake.io/#/zh/manual?id=targetadd_files">add_files</a>接口功能是非常强大的，不仅可以支持多种语言文件的混合添加构建，还可以直接添加静态库，进行自动合并库到当前的工程目标中去。</p>

<p>我们可以这么写：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"static"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"libxxx.a"</span><span class="p">,</span> <span class="s2">"lib*.a"</span><span class="p">,</span> <span class="s2">"xxx.lib"</span><span class="p">)</span>
</code></pre>
</div>

<p>直接在编译静态库的时候，合并多个已有的静态库，注意不是链接哦，这跟<a href="http://xmake.io/#/zh/manual?id=targetadd_links">add_links</a>是有区别的。</p>

<p>并且你也可以直接追加对象文件：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"objs/*.o"</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="添加自定义配置选项">添加自定义配置选项</h3>

<p>我们可以自己定义一个配置选项，例如用于启用test：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">option</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_default</span><span class="p">(</span><span class="kc">false</span><span class="p">)</span>
    <span class="n">set_showmenu</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"-DTEST"</span><span class="p">)</span>
</code></pre>
</div>

<p>然后关联到指定的target中去：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">add_options</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
</code></pre>
</div>

<p>这样，一个选项就算定义好了，如果这个选项被启用，那么编译这个target的时候，就会自动加上<code class="highlighter-rouge">-DTEST</code>的宏定义。</p>

<p>上面的设置，默认是禁用<code class="highlighter-rouge">test</code>选项的，接下来我们通过配置去启用这个选项：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake f --test<span class="o">=</span>y
<span class="gp">$ </span>xmake
</code></pre>
</div>

<p>xmake的选项支持是非常强大的，除了上述基础用法外，还可以配置各种检测条件，实现自动检测，具体详情可参考：<a href="http://xmake.io/#/zh/manual?id=optionadd_cincludes">option</a>和<a href="/cn/2016/08/06/add-package-and-autocheck/">依赖包的添加和自动检测机制</a>。</p>

<h3 id="添加第三方依赖包">添加第三方依赖包</h3>

<p>在target作用域中，添加集成第三方包依赖，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_packages</span><span class="p">(</span><span class="s2">"zlib"</span><span class="p">,</span> <span class="s2">"polarssl"</span><span class="p">,</span> <span class="s2">"pcre"</span><span class="p">,</span> <span class="s2">"mysql"</span><span class="p">)</span>
</code></pre>
</div>

<p>这样，在编译test目标时，如果这个包存在的，将会自动追加包里面的宏定义、头文件搜索路径、链接库目录，也会自动链接包中所有库。</p>

<p>用户不再需要自己单独调用<code class="highlighter-rouge">add_links</code>，<code class="highlighter-rouge">add_includedirs</code>, <code class="highlighter-rouge">add_ldflags</code>等接口，来配置依赖库链接了。</p>

<p>对于如何设置包搜索目录，可参考<a href="http://xmake.io/#/zh/manual?id=targetadd_packagedirs">add_packagedirs</a>接口，依赖包详情请参考：<a href="/cn/2016/08/06/add-package-and-autocheck/">依赖包的添加和自动检测机制</a>。</p>

<h3 id="生成配置头文件">生成配置头文件</h3>

<p>如果你想在xmake配置项目成功后，或者自动检测某个选项通过后，把检测的结果写入配置头文件，那么需要调用这个接口来启用自动生成<code class="highlighter-rouge">config.h</code>文件。</p>

<p>使用方式例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_config_h</span><span class="p">(</span><span class="s2">"$(buildir)/config.h"</span><span class="p">)</span>
    <span class="n">set_config_h_prefix</span><span class="p">(</span><span class="s2">"TB_CONFIG"</span><span class="p">)</span>
</code></pre>
</div>

<p>当这个target中通过下面的这些接口，对这个target添加了相关的选项依赖、包依赖、接口依赖后，如果某依赖被启用，那么对应的一些宏定义配置，会自动写入被设置的<code class="highlighter-rouge">config.h</code>文件中去。</p>

<ul>
  <li><a href="http://xmake.io/#/zh/manual?id=targetadd_options">add_options</a></li>
  <li><a href="http://xmake.io/#/zh/manual?id=targetadd_packages">add_packages</a></li>
  <li><a href="http://xmake.io/#/zh/manual?id=targetadd_cfuncs">add_cfuncs</a></li>
  <li><a href="http://xmake.io/#/zh/manual?id=targetadd_cxxfuncs">add_cxxfuncs</a></li>
</ul>

<p>这些接口，其实底层都用到了option选项中的一些检测设置，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">option</span><span class="p">(</span><span class="s2">"wchar"</span><span class="p">)</span>

    <span class="c1">-- 添加对wchar_t类型的检测</span>
    <span class="n">add_ctypes</span><span class="p">(</span><span class="s2">"wchar_t"</span><span class="p">)</span>

    <span class="c1">-- 如果检测通过，自动生成TB_CONFIG_TYPE_HAVE_WCHAR的宏开关到config.h</span>
    <span class="n">add_defines_h_if_ok</span><span class="p">(</span><span class="s2">"$(prefix)_TYPE_HAVE_WCHAR"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>

    <span class="c1">-- 启用头文件自动生成</span>
    <span class="n">set_config_h</span><span class="p">(</span><span class="s2">"$(buildir)/config.h"</span><span class="p">)</span>
    <span class="n">set_config_h_prefix</span><span class="p">(</span><span class="s2">"TB_CONFIG"</span><span class="p">)</span>

    <span class="c1">-- 添加对wchar选项的依赖关联，只有加上这个关联，wchar选项的检测结果才会写入指定的config.h中去</span>
    <span class="n">add_options</span><span class="p">(</span><span class="s2">"wchar"</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="检测库头文件和接口">检测库头文件和接口</h3>

<p>我们可以在刚刚生成的<code class="highlighter-rouge">config.h</code>中增加一些库接口检测，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>

    <span class="c1">-- 设置和启用config.h</span>
    <span class="n">set_config_h</span><span class="p">(</span><span class="s2">"$(buildir)/config.h"</span><span class="p">)</span>
    <span class="n">set_config_h_prefix</span><span class="p">(</span><span class="s2">"TEST"</span><span class="p">)</span>

    <span class="c1">-- 仅通过参数一设置模块名前缀</span>
    <span class="n">add_cfunc</span><span class="p">(</span><span class="s2">"libc"</span><span class="p">,</span>       <span class="kc">nil</span><span class="p">,</span>        <span class="kc">nil</span><span class="p">,</span>        <span class="p">{</span><span class="s2">"sys/select.h"</span><span class="p">},</span>   <span class="s2">"select"</span><span class="p">)</span>

    <span class="c1">-- 通过参数三，设置同时检测链接库：libpthread.a</span>
    <span class="n">add_cfunc</span><span class="p">(</span><span class="s2">"pthread"</span><span class="p">,</span>    <span class="kc">nil</span><span class="p">,</span>        <span class="s2">"pthread"</span><span class="p">,</span>  <span class="s2">"pthread.h"</span><span class="p">,</span>        <span class="s2">"pthread_create"</span><span class="p">)</span>

    <span class="c1">-- 通过参数二设置接口别名</span>
    <span class="n">add_cfunc</span><span class="p">(</span><span class="kc">nil</span><span class="p">,</span>          <span class="s2">"PTHREAD"</span><span class="p">,</span>  <span class="kc">nil</span><span class="p">,</span>        <span class="s2">"pthread.h"</span><span class="p">,</span>        <span class="s2">"pthread_create"</span><span class="p">)</span>
</code></pre>
</div>

<p>生成的<code class="highlighter-rouge">config.h</code>结果如下：</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cp">#ifndef TEST_H
#define TEST_H
</span>
<span class="c1">// 宏命名规则：$(prefix)前缀 _ 模块名（如果非nil）_ HAVE _ 接口名或者别名 （大写）
</span><span class="cp">#define TEST_LIBC_HAVE_SELECT 1
#define TEST_PTHREAD_HAVE_PTHREAD_CREATE 1
#define TEST_HAVE_PTHREAD 1
</span>
<span class="cp">#endif
</span></code></pre>
</div>

<p>这样我们在代码里面就可以根据接口的支持力度来控制代码编译了。</p>

<h3 id="自定义插件任务">自定义插件任务</h3>

<p>task域用于描述一个自定义的任务实现，与<a href="http://xmake.io/#/zh/manual?id=target">target</a>和<a href="http://xmake.io/#/zh/manual?id=option">option</a>同级。</p>

<p>例如，这里定义一个最简单的任务：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">task</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>

    <span class="c1">-- 设置运行脚本</span>
    <span class="n">on_run</span><span class="p">(</span><span class="k">function</span> <span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"hello xmake!"</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>这个任务只需要打印<code class="highlighter-rouge">hello xmake!</code>，那如何来运行呢？</p>

<p>由于这里没有使用<a href="http://xmake.io/#/zh/manual?id=taskset_menu">set_menu</a>设置菜单，因此这个任务只能在<code class="highlighter-rouge">xmake.lua</code>的自定义脚本或者其他任务内部调用，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>

    <span class="n">after_build</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span>

        <span class="c1">-- 导入task模块</span>
        <span class="n">import</span><span class="p">(</span><span class="s2">"core.project.task"</span><span class="p">)</span>

        <span class="c1">-- 运行hello任务</span>
        <span class="n">task</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>此处在构建完test目标后运行hello任务，当然我们还可以传递参数哦:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">task</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>
    <span class="n">on_run</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="n">arg3</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"hello xmake!"</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="n">arg3</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">after_build</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span>
        <span class="n">import</span><span class="p">(</span><span class="s2">"core.project.task"</span><span class="p">)</span>
        <span class="n">task</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">,</span> <span class="p">{},</span> <span class="s2">"arg1"</span><span class="p">,</span> <span class="s2">"arg2"</span><span class="p">,</span> <span class="s2">"arg3"</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>上述<code class="highlighter-rouge">task.run</code>的<code class="highlighter-rouge"><span class="p">{}</span></code>这个是用于传递插件菜单中的参数，这里没有通过<a href="http://xmake.io/#/zh/manual?id=taskset_menu">set_menu</a>设置菜单，此处传空。</p>

<p>xmake的插件支持也是功能很强大的，并且提供了很多内置的使用插件，具体请参考：<a href="http://xmake.io/#/zh/plugins?id=%E7%AE%80%E4%BB%8B">xmake插件手册</a>和<a href="http://xmake.io/#/zh/manual?id=%E6%8F%92%E4%BB%B6%E4%BB%BB%E5%8A%A1">task手册</a></p>

<p>或者可以参考xmake自带的一些<a href="https://github.com/xmake-io/xmake/blob/master/xmake/plugins/echo/xmake.lua">插件demo</a>。</p>

<h3 id="另外一种语法风格">另外一种语法风格</h3>

<p>xmake除了支持最常使用的<code class="highlighter-rouge">set-add</code>描述风格外，还支持另外一种语法风格：<code class="highlighter-rouge">key-val</code>，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span>
<span class="p">{</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s2">"test"</span><span class="p">,</span>
    <span class="n">defines</span> <span class="o">=</span> <span class="s2">"DEBUG"</span><span class="p">,</span>
    <span class="n">files</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"test/*.cpp"</span><span class="p">}</span>
<span class="p">}</span>
</code></pre>
</div>

<p>这个等价于：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"static"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"DEBUG"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"test/*.cpp"</span><span class="p">)</span>
</code></pre>
</div>

<p>用户可以根据自己的喜好来选择合适的风格描述，但是这边的建议是：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>* 针对简单的工程，不需要太过复杂的条件编译，可以使用key-val方式，更加精简，可读性好
* 针对复杂工程，需要更高的可控性，和灵活性的话，建议使用set-add方式
* 尽量不要两种风格混着写，虽然是支持的，但是这样对整个工程描述会感觉很乱，因此尽量统一风格作为自己的描述规范
</code></pre>
</div>

<p>另外，不仅对target，像option, task, template都是支持两种方式设置的，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- set-add风格</span>
<span class="n">option</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_default</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
    <span class="n">set_showmenu</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
    <span class="n">set_category</span><span class="p">(</span><span class="s2">"option"</span><span class="p">)</span>
    <span class="n">set_description</span><span class="p">(</span><span class="s2">"Enable or disable the demo module"</span><span class="p">,</span> <span class="s2">"    =y|n"</span><span class="p">)</span>
</code></pre>
</div>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- key-val风格</span>
<span class="n">option</span>
<span class="p">{</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s2">"demo"</span><span class="p">,</span>
    <span class="n">default</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span>
    <span class="n">showmenu</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span>
    <span class="n">category</span> <span class="o">=</span> <span class="s2">"option"</span><span class="p">,</span>
    <span class="n">desciption</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"Enable or disable the demo module"</span><span class="p">,</span> <span class="s2">"    =y|n"</span><span class="p">}</span>
<span class="p">}</span>
</code></pre>
</div>

<p>自定义的任务或者插件可以这么写：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- set-add风格</span>
<span class="n">task</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>
    <span class="n">on_run</span><span class="p">(</span><span class="k">function</span> <span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"hello xmake!"</span><span class="p">)</span>

    <span class="k">end</span><span class="p">)</span>
    <span class="n">set_menu</span> <span class="p">{</span>
        <span class="n">usage</span> <span class="o">=</span> <span class="s2">"xmake hello [options]"</span><span class="p">,</span>
        <span class="n">description</span> <span class="o">=</span> <span class="s2">"Hello xmake!"</span><span class="p">,</span>
        <span class="n">options</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="p">}</span>
</code></pre>
</div>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- key-val风格</span>
<span class="n">task</span>
<span class="p">{</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s2">"hello"</span><span class="p">,</span>
    <span class="n">run</span> <span class="o">=</span> <span class="p">(</span><span class="k">function</span> <span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"hello xmake!"</span><span class="p">)</span>
    <span class="k">end</span><span class="p">),</span>
    <span class="n">menu</span> <span class="o">=</span> <span class="p">{</span>
                <span class="n">usage</span> <span class="o">=</span> <span class="s2">"xmake hello [options]"</span><span class="p">,</span>
                <span class="n">description</span> <span class="o">=</span> <span class="s2">"Hello xmake!"</span><span class="p">,</span>
                <span class="n">options</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="p">}</span>
<span class="p">}</span>
</code></pre>
</div>

<h3 id="结语">结语</h3>

<p>更多描述说明，可直接阅读<a href="http://xmake.io/#/zh/manual">xmake的官方手册</a>，上面提供了完整的api文档和使用描述。</p>

        </article>
        <hr>

        <!-- baidu ads -->
        

        <!-- reward -->
        <div style="text-align: center;">
            <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
              <span>赏</span>
            </button>
            <div id="QR" style="display: none;">
                <div id="wechat" style="display: inline-block">
                  <img id="wechat_qr" src="/static/img/weixin.png" alt="WeChat Pay"/>
                  <p>微信打赏</p>
                </div>
                <div id="alipay" style="display: inline-block">
                  <img id="alipay_qr" src="/static/img/alipay.png" alt="Alipay"/>
                  <p>支付宝打赏</p>
                </div>
            </div>
        </div>

        
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
        

        
        
            
        
            
            
            
                
                    
                        
                        <h2 id="similar_posts">相关文章</h2>
                        <ul>
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/17/xmake-update-v2.6.2/">xmake v2.6.2 发布，新增 Linux 内核驱动模块构建支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 发布，使用 Lua5.4 运行时，Rust 和 C++ 混合编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/30/xmake-update-v2.5.9/">xmake v2.5.9 发布，改进 C++20 模块，并支持 Nim, Keil MDK 和 Unity Build
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 发布，新增 Pascal/Swig 程序和 Lua53 运行时支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/08/29/xmake-update-v2.5.7/">xmake v2.5.7 发布，包依赖锁定和 Vala/Metal 语言编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
        
            </ul>
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        

        

        

        
        
        <p><strong>上一篇</strong> <a href="/cn/2017/04/02/update-v2.1.3/">xmake v2.1.3版本更新，修复安全和稳定性问题</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        <p><strong>下一篇</strong> <a href="/cn/2017/05/10/update-v2.1.4/">xmake v2.1.4版本更新，增加交互式命令执行(REPL)</a></p>
        
    </div>
</div>


        <h2 id="comments">评论</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,       
  language: 'zh-CN',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">

            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    内容
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#english">English</a></li>
                    <li><a href="#similar_posts">相关文章</a></li>
                    <li><a href="#comments">评论</a></li>
                </ul>
            </div>


            <!-- baidu ads -->
            
            
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    链接
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- xmake courses -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    xmake 入门课程
                </div>
                <a href="https://xmake.io/#/zh-cn/about/course" target="_blank">
                <img src="/static/img/xmake-course.png" alt="course" width="256" height="193">
                </a>
            </div>

            <!-- qqgroup -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    技术交流群（QQ）
                </div>
                <img src="/static/img/qqgroup.png" alt="qqgroup" width="256" height="284">
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
